<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>实体变更日志测试</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css">
</head>
<body>
    <div class="container-fluid mt-4">
        <h2>实体变更日志测试</h2>
        
        <div class="card mb-4">
            <div class="card-header">
                <h5>创建商品测试</h5>
            </div>
            <div class="card-body">
                <form id="createProductForm">
                    <div class="row">
                        <div class="col-md-4">
                            <div class="form-group">
                                <label for="standardName">标准品名</label>
                                <input type="text" class="form-control" id="standardName" name="standardName" value="测试商品">
                            </div>
                        </div>
                        <div class="col-md-4">
                            <div class="form-group">
                                <label for="commonName">习惯称谓</label>
                                <input type="text" class="form-control" id="commonName" name="commonName" value="测试商品">
                            </div>
                        </div>
                        <div class="col-md-4">
                            <div class="form-group">
                                <label for="category">商品分类</label>
                                <input type="text" class="form-control" id="category" name="category" value="测试分类">
                            </div>
                        </div>
                    </div>
                    <button type="button" class="btn btn-primary" onclick="createProduct()">创建商品</button>
                </form>
            </div>
        </div>
        
        <div class="card mb-4">
            <div class="card-header">
                <h5>查询实体变更日志</h5>
            </div>
            <div class="card-body">
                <form id="queryLogForm">
                    <div class="row">
                        <div class="col-md-3">
                            <div class="form-group">
                                <label for="logPage">页码</label>
                                <input type="number" class="form-control" id="logPage" name="page" value="1" min="1">
                            </div>
                        </div>
                        <div class="col-md-3">
                            <div class="form-group">
                                <label for="logLimit">每页条数</label>
                                <input type="number" class="form-control" id="logLimit" name="limit" value="10" min="1" max="100">
                            </div>
                        </div>
                        <div class="col-md-3">
                            <div class="form-group">
                                <label>&nbsp;</label>
                                <div>
                                    <button type="button" class="btn btn-primary" onclick="queryEntityLogs()">查询日志</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
        
        <div class="card">
            <div class="card-header">
                <h5>响应结果</h5>
            </div>
            <div class="card-body">
                <pre id="result" style="background-color: #f8f9fa; padding: 15px; border-radius: 5px; max-height: 500px; overflow-y: auto;">
// 点击按钮查看结果
                </pre>
            </div>
        </div>
    </div>
    
    <script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js"></script>
    <script>
        let createdProductId = null;
        
        // 创建商品
        function createProduct() {
            const productData = {
                standardName: $('#standardName').val(),
                commonName: $('#commonName').val(),
                category: $('#category').val(),
                standardWeight: 10.5,
                grossWeight: 12.0,
                unitPrice: 5.0
            };
            
            $.ajax({
                url: '/products/save',
                method: 'POST',
                contentType: 'application/json',
                data: JSON.stringify(productData),
                success: function(data) {
                    $('#result').text('创建商品成功:\n' + JSON.stringify(data, null, 2));
                    // 创建成功后查询日志
                    setTimeout(queryEntityLogs, 1000);
                },
                error: function(xhr) {
                    $('#result').text('创建商品失败: ' + xhr.responseText);
                }
            });
        }
        
        // 查询实体变更日志
        function queryEntityLogs() {
            const formData = $('#queryLogForm').serialize();
            
            $.get('/sys/entityChangeLog/list?' + formData)
                .done(function(data) {
                    $('#result').text('实体变更日志查询结果:\n' + JSON.stringify(data, null, 2));
                })
                .fail(function(xhr) {
                    $('#result').text('查询日志失败: ' + xhr.responseText);
                });
        }
        
        // 页面加载完成后查询一次
        $(document).ready(function() {
            queryEntityLogs();
        });
    </script>
</body>
</html>